﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Content;
using RebEngine.Managers;
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Intermediate;
using System.Xml;

namespace RebellionII.GameObjects
{
public class RebellionContainer
    {
        [ContentSerializer]
        List<Troop> Troops = new List<Troop>();
        [ContentSerializer]
        List<CapitalShip> CapitalShips = new List<CapitalShip>();
        [ContentSerializer]
        List<Fighter> Fighters = new List<Fighter>();
        [ContentSerializer]
        List<Facility> Facilities = new List<Facility>();
        [ContentSerializer]
        List<Character> Characters = new List<Character>();
        
        string teamString;
        public RebellionContainer()
        {
        }

        public RebellionContainer(string teamString2)
        {
            teamString = teamString2;
            //AddTroops();
            //AddCaps();
            //AddFighters();
            //AddFacilities();
            //AddCharacters();
#region XMLWRiter            
            /*This was used to create the original XML files
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Indent = true;
            
            using (XmlWriter writer = XmlWriter.Create("Content/XML/CapitalShips.xml", settings))
            {
                IntermediateSerializer.Serialize(writer, CapitalShips, null);
              
            }
            using (XmlWriter writer = XmlWriter.Create("Content/XML/Fighters.xml", settings))
            {
                IntermediateSerializer.Serialize(writer, Fighters, null);

            } 
            using (XmlWriter writer = XmlWriter.Create("Content/XML/Facilities.xml", settings))
            {
                IntermediateSerializer.Serialize(writer, Facilities, null);

            } 
            using (XmlWriter writer = XmlWriter.Create("Content/XML/Characters.xml", settings))
            {
                IntermediateSerializer.Serialize(writer, Characters, null);

            }
            using (XmlWriter writer = XmlWriter.Create("Content/XML/Troops.xml", settings))
            {
                IntermediateSerializer.Serialize(writer, Troops, null);

            }
            */
#endregion
            
        }

        private void AddCharacters()
        {
            using (XmlReader writer = XmlReader.Create("Content/XML/" + teamString + "Characters.xml"))
            {
                Characters = IntermediateSerializer.Deserialize<List<Character>>(writer, "char.data");
            }
        }

        private void AddTroops()
        {
            using (XmlReader writer = XmlReader.Create("Content/XML/" + teamString + "Troops.xml"))
            {
                Troops = IntermediateSerializer.Deserialize<List<Troop>>(writer, "troop.data");
            }
        }

        private void AddCaps()
        {
            using (XmlReader writer = XmlReader.Create("Content/XML/" + teamString + "CapShips.xml"))
            {
                CapitalShips = IntermediateSerializer.Deserialize<List<CapitalShip>>(writer, "Cap.data");
            }
        }

        private void AddFighters()
        {
            using (XmlReader writer = XmlReader.Create("Content/XML/" + teamString + "Fighters.xml"))
            {
                Fighters = IntermediateSerializer.Deserialize<List<Fighter>>(writer, "fight.data");
            }

        }

        private void AddFacilities()
        {
            using (XmlReader writer = XmlReader.Create("Content/XML/" + teamString + "Facilities.xml"))
            {
                Facilities = IntermediateSerializer.Deserialize<List<Facility>>(writer, "Fac.data");
            }
        }
    }

}
